import request from '@/utils/request'
import type { PageParam, ResponseData } from '../commonType'

enum API {
  PAGE_URL = '/sys/role/getPage',
  ADD_URL = '/sys/role/add',
  EDIT_URL = '/sys/role/update',
  DELETE_URL = '/sys/role/batchDelete',
  PAGE_ALL_URL = '/sys/role/getAll',
  GET_AUTH_URL = '/sys/role/getRoleAuth',
  GRANT_AUTH_URL = '/sys/role/grantAuth',
}

export function roleGetPage(data: PageParam) {
  return request.get<any, ResponseData>(API.PAGE_URL, { params: data })
}

export function roleAdd(data: any) {
  return request.post<any, ResponseData>(API.ADD_URL, data)
}

export function roleEdit(data: any) {
  return request.put<any, ResponseData>(API.EDIT_URL, data)
}

export function roleDelete(ids: Array<string | number>) {
  return request.delete<any, ResponseData>(API.DELETE_URL, { data: { ids } })
}

export function roleGetAll() {
  return request.get<any, ResponseData>(API.PAGE_ALL_URL)
}

export function roleGetAuth(data: { roleId: string }) {
  return request.get<any, ResponseData>(API.GET_AUTH_URL, { params: data })
}

export function roleGrantAuth(data: any) {
  return request.put<any, ResponseData>(API.GRANT_AUTH_URL, data)
}
